Goto

Collaborating Authors

 implementing naive baye


Implementing Naive Bayes From Scratch

#artificialintelligence

As stated in the general overview, we need to calculate the summary statistics for each class (and feature) as well as the prior. First of all, we need to gather some basic information about the dataset and create three zero-matrices to store the mean, the variance, and the prior for each class. Next, we iterate over all the classes, compute the statistics and update our zero-matrices accordingly. For example, assume we have two unique classes (0,1) and two features in our dataset. The matrix storing the mean values, therefore will have a two rows and two columns (2x2). The prior is just a single vector (1x2), containing the ratio of a single classes' samples divided by the total sample size.


Implementing Naive Bayes for Sentiment Analysis in Python

#artificialintelligence

The Naive Bayes Classifier is a well known machine learning classifier with applications in Natural Language Processing (NLP) and other areas. Despite its simplicity, it is able to achieve above average performance in different tasks like sentiment analysis. Today we will elaborate on the core principles of this model and then implement it in Python. In the end, we will see how well we do on a dataset of 2000 movie reviews. The math behind this model isn't particularly difficult to understand if you are familiar with some of the math notation.